<?php
namespace app\index\model;
use think\Db;
use think\Model;

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/1/12
 * Time: 12:20
 */
class Coupon extends Model
{
    protected $name='coupon';

    public function getlist(){
        return $this->where('status',1)
            ->field('id,id as isselect,title,price,FROM_UNIXTIME(atime,"%Y-%m-%d") as atime,FROM_UNIXTIME(btime,"%Y-%m-%d") as btime,total_price')
            ->order('id desc')
            ->select();
    }

    public function getIsselectAttr($v)
    {
        $data = Db::name('coupon_h')->where(['user_id'=>input('id'), 'coupon_id'=>$v])->find();
        if (!empty($data)){
            return 1;
        }else{
            return 0;
        }
    }

}